package com.eleadmin.common.system.service.impl;
import com.eleadmin.common.system.mapper.GoodsMapper;
import com.eleadmin.common.system.param.Goods;
import com.eleadmin.common.system.param.req.GoodsRequest;
import com.eleadmin.common.system.param.result.PageResult;
import com.eleadmin.common.system.param.result.Result;
import com.eleadmin.common.system.service.GoodsSercice;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceimpl implements GoodsSercice {
    @Autowired
    GoodsMapper goodsMapper;


    @Override
    public Result<PageResult<Goods>> list(GoodsRequest goodsRequest) {
        PageHelper.startPage(goodsRequest.getPageNum(),goodsRequest.getPageSize());

        List<Goods> list= goodsMapper.list(goodsRequest);

        PageInfo<Goods> goodsPageInfo = new PageInfo<>();

        return PageResult.toResult(goodsPageInfo.getTotal(),list);
    }

    @Override
    public Result goodsDel(Integer id) {
        Integer i=goodsMapper.goodsDel(id);
        return Result.success(i>0?200:500,i>0?"删除成功":"删除失败");
    }

    @Override
    public Result goodsAdd(Goods goods) {
        Integer i=goodsMapper.goodsAdd(goods);
        return Result.success(i>0?200:500,i>0?"添加成功":"删除失败");
    }

    @Override
    public List<Goods> Districtout() {
        List<Goods> list=goodsMapper.Districtout();
        return list;
    }
}
